<template>
  <page-header-wrapper :title="false">
    <a-card title="商标检索">
      <a-tabs type="card" default-active-key="1">
        <a-tab-pane key="1" tab="公海商标"></a-tab-pane>
        <!--        <a-tab-pane key="2" tab="自持商标" disabled></a-tab-pane>-->
      </a-tabs>
      <div class="table-page-search-wrapper">
        <a-form-model
          layout="inline"
          :model="queryParam"
        >
          <a-row :gutter="15">
            <a-col :md="6" :sm="24">
              <a-form-model-item label="商标类别">
                <a-select v-model="queryParam['filter[category]']" placeholder="请选择商标类别" :allowClear="true">
                  <a-select-option v-for="(item,index) in categoryOpts" :key="index" :value="index">{{item}}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="关键字">
                <a-input v-model="queryParam['filter[tm_name]']" placeholder="请输入关键字" />
              </a-form-item>
            </a-col>
            <template v-if="advanced">
              <a-col :md="6" :sm="24">
                <a-form-item label="商标字数">
                  <a-input v-model="queryParam['filter[words_num]']" placeholder="请输入商标字数" />
                </a-form-item>
              </a-col>
            </template>
            <a-col :md="!advanced && 8 || 24" :sm="24">
              <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                <a-button type="primary" @click="onSearch">查询</a-button>
                <a-button style="margin-left: 8px" @click="resetForm">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <div class="table-operator" v-show="showList">
        <s-table
          ref="table"
          bordered
          size="middle"
          :row-key="(record) => record.id"
          :columns="buyColumns"
          :data="buyData"
        >
          <div
            slot="filterDropdown"
            slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
            style="padding: 8px"
          >
            <a-input
              v-ant-ref="c => (searchInput = c)"
              :placeholder="`搜索${column.title}`"
              :value="selectedKeys[0]"
              style="width: 188px; margin-bottom: 8px; display: block;"
              @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
              @pressEnter="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
            />
            <a-button
              type="primary"
              icon="search"
              size="small"
              style="width: 90px; margin-right: 8px"
              @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
            >
              搜索
            </a-button>
            <a-button size="small" style="width: 90px" @click="() => handleReset(clearFilters, column.dataIndex)">
              重置
            </a-button>
          </div>
          <div
            slot="filterType"
            slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
            style="padding: 8px"
          >
            <a-select
              :placeholder="`选择${column.title}`"
              style="width: 188px; margin-bottom: 8px; display: block;"
              :value="selectedKeys[0]"
              @change="(value) => setSelectedKeys(value ? [value] : [])"
              @pressEnter="() => handleSelect(selectedKeys, confirm, column.dataIndex)"
            >
              <a-select-option v-for="(item, index) in tmTypeOpts" :value="index" :key="index">{{item}}</a-select-option>
            </a-select>
            <a-button
              type="primary"
              icon="search"
              size="small"
              style="width: 90px; margin-right: 8px"
              @click="() => handleSelect(selectedKeys, confirm, column.dataIndex)"
            >
              搜索
            </a-button>
            <a-button size="small" style="width: 90px" @click="() => handleReset(clearFilters, column.dataIndex)">
              重置
            </a-button>
          </div>
          <div
            slot="filterCategory"
            slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
            style="padding: 8px"
          >
            <a-select
              :placeholder="`选择${column.title}`"
              style="width: 188px; margin-bottom: 8px; display: block;"
              :value="selectedKeys[0]"
              @change="(value) => setSelectedKeys(value ? [value] : [])"
              @pressEnter="() => handleSelect(selectedKeys, confirm, column.dataIndex)"
            >
              <a-select-option v-for="(item, index) in categoryOpts" :value="index" :key="index">{{item}}</a-select-option>
            </a-select>
            <a-button
              type="primary"
              icon="search"
              size="small"
              style="width: 90px; margin-right: 8px"
              @click="() => handleSelect(selectedKeys, confirm, column.dataIndex)"
            >
              搜索
            </a-button>
            <a-button size="small" style="width: 90px" @click="() => handleReset(clearFilters, column.dataIndex)">
              重置
            </a-button>
          </div>
          <template slot="is_company" slot-scope="text">
            {{isCompanyOpts[text]}}
          </template>
          <template slot="tm_type" slot-scope="text">
            {{tmTypeOpts[text]}}
          </template>
          <template slot="tm_status" slot-scope="text">
            <a-tag color="red">{{tmStatusOpts[text]}}</a-tag>
          </template>
          <template slot="is_nz_fee" slot-scope="text">
            {{isNzOpts[text]}}
          </template>
          <template slot="action" slot-scope="text,record">
            <a-button
              :disabled="record.tm_status != 10"
              :loading="loading"
              size="small"
              type="primary"
              icon="plus"
              @click="addModal(record.id)"
            >
              提交意向
            </a-button>
          </template>
        </s-table>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
  import { STable } from '@/components'
  import { getTradeList } from '@/api/transaction'
  import transactionColumns from '@/columns/transaction'

  export default {
    name: 'BuyTrademark',
    components: { STable },
    data () {
      return {
        loading: false,
        visible: false,
        showList: false,
        showNone: false,
        advanced: true,
        queryParam: {},
        buyColumns: transactionColumns.buy,
        buyData: parameters => {
          return getTradeList(Object.assign(parameters, this.queryParam)).then(res => {
            this.categoryOpts = res.result.category_opts
            this.total = res.result.total_count
            this.tmTypeOpts = res.result.tm_type_opts
            this.tmStatusOpts = res.result.tm_status_opts
            this.isCompanyOpts = res.result.isCompanyOpts
            this.isNzOpts = res.result.nz_fee_opts
            return res.result
          })
        },
        categoryOpts: {},
        gid: '',
        category: '',
        groups: '',
        appTypeOpts: {},
        tmStatusOpts: {},
        tmTypeOpts: {},
        isCompanyOpts: {},
        isNzOpts: {},
        total: 0,
        searchInput: null,
        searchText: '',
        searchedColumn: ''
      }
    },
    methods: {
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      resetForm () {
        this.queryParam = {}
        this.showList = false
        this.$refs.table.refresh(true)
      },
      onSearch () {
        this.showList = false
        this.$refs.table.refresh(true)
        this.showList = true
      },
      onCancel (visible) {
        this.visible = visible
      },
      handleSearch (selectedKeys, confirm, dataIndex) {
        confirm()
        this.searchText = selectedKeys[0]
        this.searchedColumn = dataIndex
        this.queryParam['filter[' + dataIndex + ']'] = selectedKeys[0]
      },
      handleSelect (selectedKeys, confirm, dataIndex) {
        confirm()
        this.searchText = selectedKeys[0]
        this.searchedColumn = dataIndex
        this.queryParam['filter[' + dataIndex + ']'] = selectedKeys[0]
      },
      handleReset (clearFilters, dataIndex) {
        clearFilters()
        delete this.queryParam['filter[' + dataIndex + ']']
      }
    }
  }
</script>

<style scoped>

</style>
